<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title></title>
  <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">

  <link rel="stylesheet" href="../css/mui.css">
  <link rel="stylesheet" href="../css/mui.picker.css" />
  <link rel="stylesheet" href="../css/mui.poppicker.css" />
  <link rel="stylesheet" href="http://cdn.amazeui.org/amazeui/2.7.2/css/amazeui.css">

  <style>
    .mui-content>.mui-table-view {
      margin-top: 15px;
    }
    
    .mui-content>.mui-table-view:first-child {
      margin-top: 0 !important;
    }
    
    .pc-table-view {
      color: #8f8f94;
      font-size: 14px;
    }
    
    #head-img1 {
      vertical-align: middle;
      width: 60px;
      border-radius: 50%;
      margin-left: 20px;
    }
    
    .pc-dis {
      display: flex !important;
    }
    
    .pc-mar-left {
      margin-left: 20px;
    }
    
    .pc-color-black {
      font-size: 14px;
      color: #444;
    }
    
    .btn-wrap {
      margin-bottom: 15px;
    }
  </style>

</head>

<body>
  <header class="mui-bar mui-bar-nav">
    <!-- <a class="mui-action-back1 mui-icon mui-icon-left-nav mui-pull-left" id="goBack"></a> -->
    <!-- <a class="mui-icon mui-icon-left-nav" id="goBack"></a> -->
    <span class="mui-icon mui-icon-left-nav" id="goBack"></span>
    <h1 class="mui-title">编辑个人资料</h1>
  </header>

  <div class="mui-content">
    <ul class="mui-table-view pc-table-view">
      <li class="mui-table-view-cell">
        <a id="head" class="mui-navigate-right">头像
           <img class="head-img mui-action-preview pc-margin-left" id="head-img1" src="../images/avator-demo.jpg"/>
          <!--<img class="head-img mui-action-preview pc-margin-left" id="head-img1" src="http://iph.href.lu/180x180?text=大管家"/>-->
          <span class="mui-pull-right head"></span>
        </a>
      </li>
      <li class="mui-table-view-cell">
        <a class="pc-dis" id="setName">昵称
          <div class="mui-navigate-right pc-mar-left"><span class="mui-pull-left person" id="showName">起个有趣的昵称吧...</span></div>
				</a>
      </li>
      <li class="mui-table-view-cell">
        <a class="pc-dis" id="build_qrcode">我的二维码
          <div class="mui-navigate-right pc-mar-left"></div>
				</a>
      </li>
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="setGender">性别<span class="mui-pull-right pc-mar-left person" id="showGender">先生or女士</span></a>
      </li>
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="setAge">年龄<span class="mui-pull-right pc-mar-left person" id="showAge">几零后呢</span></a>
      </li>
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="setSignature">签名<span class="mui-pull-right pc-mar-left person" id="showSignature">给自己来个口号吧</span></a>
      </li>
    </ul>

    <ul class="mui-table-view pc-table-view">
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="setIndustry">行业<span class="mui-pull-right pc-mar-left person" id="showIndustry">选择所在行业</span></a>
      </li>
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="setCompany">公司<span class="mui-pull-right pc-mar-left person" id="showCompany">填写所在公司</span></a>
      </li>
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="setWork">职业<span class="mui-pull-right pc-mar-left person" id="showWork">填写你的公司</span></a>
      </li>
    </ul>

    <ul class="mui-table-view pc-table-view">
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="setHometown">家乡<span class="mui-pull-right pc-mar-left person" id="showHometown">选择你的家乡</span></a>
      </li>
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="setHobby">爱好<span class="mui-pull-right pc-mar-left person" id="showHobby">选择你的爱好</span></a>
      </li>
    </ul>

    <ul class="mui-table-view pc-table-view">
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right">出工次数<span class="mui-pull-right pc-mar-left person">出工才有次数噢 </span></a>
      </li>
      <!-- <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right">收入<span class="mui-pull-right pc-mar-left pc-color-black">88.99元</span></a>
      </li> -->
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="validateName">实名认证<span class="mui-pull-right pc-mar-left person">未认证</span></a>
      </li>
      <!-- <li class="mui-table-view-cell">
        <a href="upload_shiming.html" class="pc-dis mui-navigate-right">照片识别<span class="mui-pull-right pc-mar-left">未识别</span></a>
      </li>
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right">支付验证<span class="mui-pull-right pc-mar-left">未验证</span></a>
      </li> -->
      <li class="mui-table-view-cell">
        <!-- <a class="pc-dis mui-navigate-right" id="setGoodat">擅长<span class="mui-pull-right pc-mar-left" id="showGoodat">(3-5分钟个人写真)</span></a> -->
        <a class="pc-dis mui-navigate-right" id="setGoodat">擅长<span class="mui-pull-right pc-mar-left person" id="showGoodat">说出你的能力...</span></a>
      </li>
      <!-- <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right">积分<span class="mui-pull-right pc-mar-left score">发帮助有积分噢</span></a>
      </li> -->
      <!-- <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right">信任值<span class="mui-pull-right pc-mar-left">80分</span></a>
      </li> -->
      <li class="mui-table-view-cell">
        <a class="pc-dis mui-navigate-right" id="uploadZizhi">个人资质证书<span class="mui-pull-right pc-mar-left person">未上传</span></a>
      </li>
    </ul>

  </div>

  <div class="am-modal am-modal-prompt" tabindex="-1" id="my-prompt">
    <div class="am-modal-dialog">
      <div class="am-modal-hd">设置登录密码</div>
      <div class="am-modal-bd">
        <input type="password" class="am-modal-prompt-input" placeholder="请输入8-16位密码">
        <p style="text-align: left; font-size: 10px; margin: 0;">须包含“数字、字母、符号”中至少2种元素</p>
        <p style="text-align: left; font-size: 10px; margin: 0;">密码长度8-16位</p>
      </div>
      <div class="am-modal-footer">
        <span class="am-modal-btn" data-am-modal-confirm>确定</span>
      </div>
    </div>
  </div>

  <!-- 升级VIP模态窗口 -->
  <div class="am-modal am-modal-confirm" tabindex="-1" id="vip-confirm">
    <div class="am-modal-dialog">
      <div class="am-modal-hd">大管家VIP会员</div>

      <div class="am-modal-footer" style="margin-top: 5px;">
        <div class="btn-wrap">
          <button class="am-btn am-btn-primary am-radius" data-am-modal-confirm>升级成为VIP会员</button>

        </div>
        <div class="btn-wrap">
          <button class="am-btn am-btn-default am-radius" data-am-modal-cancel>不了,谢谢</button>

        </div>
      </div>
    </div>
  </div>

  <!-- 我的二维码模态窗口 -->
  <div class="am-modal am-modal-prompt" tabindex="-1" id="qrcode_prompt">
    <div class="am-modal-dialog">
      <div class="am-modal-hd">我的二维码</div>
      <div class="am-modal-bd" id="show_qrcode"></div>
      <div class="am-modal-footer">
        推荐码：<mark></mark>
      </div>
    </div>
  </div>

</body>

<script src="../js/mui.js "></script>
<script src="https://cdn.bootcss.com/jquery/3.3.1/jquery.js"></script>
<script src="http://cdn.amazeui.org/amazeui/2.7.2/js/amazeui.js"></script>
<script src="../js/mui.picker.js"></script>
<script src="../js/mui.poppicker.js"></script>
<!-- <script src="../js/mui.view.js"></script> -->
<!-- <script src='../js/feedback.js'></script> -->
<script src="../js/app.js"></script>
<script src="../js/http.js"></script>
<script>
  window.onload = function() {
    readPerson();

  }

  var shares = {},
    setNameEle = document.getElementById('setName'),
    showNameEle = document.getElementById('showName'),
    setGenderEle = document.getElementById('setGender'),
    showGenderEle = document.getElementById('showGender'),
    setAgeEle = document.getElementById('setAge'),
    showAgeEle = document.getElementById('showAge'),
    setSignatureEle = document.getElementById('setSignature'),
    showSignatureEle = document.getElementById('showSignature'),
    setGoodatEle = document.getElementById('setGoodat'),
    showGoodatEle = document.getElementById('showGoodat'),
    setIndustryEle = document.getElementById('setIndustry'),
    showIndustryEle = document.getElementById('showIndustry'),
    setCompanyEle = document.getElementById('setCompany'),
    showCompanyEle = document.getElementById('showCompany'),
    setWorkEle = document.getElementById('setWork'),
    showWorkEle = document.getElementById('showWork'),
    setHometownEle = document.getElementById('setHometown'),
    showHometownEle = document.getElementById('showHometown'),
    setHobbyEle = document.getElementById('setHobby'),
    showHobbyEle = document.getElementById('showHobby'),
    genderSel = new mui.PopPicker(),
    genderOption = [{
      value: 'man',
      text: '男'
    }, {
      value: 'women',
      text: '女'
    }],
    ageSel = new mui.PopPicker(),
    ageOption = [{
      value: '90s',
      text: '90后'
    }, {
      value: '80s',
      text: '80后'
    }, {
      value: '70s',
      text: '70后'
    }, {
      value: '60s',
      text: '60后'
    }, {
      value: '50s',
      text: '50后'
    }],
    industrySel = new mui.PopPicker(),
    industryOption = [{
      value: 'hlw',
      text: '互联网软件'
    }, {
      value: 'txyj',
      text: '通信硬件'
    }, {
      value: 'fdc',
      text: '房地产建筑'
    }, {
      value: 'whcm',
      text: '文化传媒'
    }, {
      value: 'jr',
      text: '金融类'
    }, {
      value: 'xfp',
      text: '消费品'
    }, {
      value: 'qcjx',
      text: '汽车机械'
    }, {
      value: 'jxfy',
      text: '教育翻译'
    }, {
      value: 'mywl',
      text: '贸易物流'
    }, {
      value: 'swyl',
      text: '生物医疗'
    }, {
      value: 'nyhg',
      text: '能源化工'
    }, {
      value: 'zfjg',
      text: '政府机构'
    }, {
      value: 'fwy',
      text: '服务业'
    }, {
      value: 'qthy',
      text: '其他行业'
    }, {
      value: 'zxxs',
      text: '在校学生'
    }],
    hometownSel = new mui.PopPicker(),
    hometownOption = [{
      value: 'bj',
      text: '北京'
    }, {
      value: 'tj',
      text: '天津'
    }, {
      value: 'hb',
      text: '河北'
    }, {
      value: 'sx',
      text: '山西'
    }, {
      value: 'nmg',
      text: '内蒙古'
    }, {
      value: 'ln',
      text: '辽宁'
    }, {
      value: 'jl',
      text: '吉林'
    }, {
      value: 'hlj',
      text: '黑龙江'
    }, {
      value: 'sh',
      text: '上海'
    }, {
      value: 'js',
      text: '江苏'
    }, {
      value: 'zj',
      text: '浙江'
    }, {
      value: 'ah',
      text: '安徽'
    }, {
      value: 'fj',
      text: '福建'
    }, {
      value: 'jx',
      text: '江西'
    }, {
      value: 'sd',
      text: '山东'
    }],
    hobbySel = new mui.PopPicker(),
    hobbyOption = [{
      value: 'yd',
      text: '运动'
    }, {
      value: 'ms',
      text: '美食'
    }, {
      value: 'dy',
      text: '电影'
    }, {
      value: 'ly',
      text: '旅游'
    }, {
      value: 'dm',
      text: '动漫'
    }, {
      value: 'yd',
      text: '阅读'
    }],
    personInfo = {}, // 存放个人信息
    uploadZizhiEle = document.getElementById('uploadZizhi'),
    validateNameEle = document.getElementById('validateName'),
    goBackEle = document.getElementById('goBack');

  genderSel.setData(genderOption);
  ageSel.setData(ageOption);
  industrySel.setData(industryOption);
  hometownSel.setData(hometownOption);
  hobbySel.setData(hobbyOption);

  setNameEle.addEventListener('tap', setName);
  setGenderEle.addEventListener('tap', setGender);
  setAgeEle.addEventListener('tap', setAge);
  setSignatureEle.addEventListener('tap', setSignature);
  setGoodatEle.addEventListener('tap', setGoodat);
  setIndustryEle.addEventListener('tap', setIndustry);
  setCompanyEle.addEventListener('tap', setCompany);
  setWorkEle.addEventListener('tap', setWork);
  setHometownEle.addEventListener('tap', setHometown);
  setHobbyEle.addEventListener('tap', setHobby);
  uploadZizhiEle.addEventListener('tap', toUploadZizhi);
  validateNameEle.addEventListener('tap', toValidateName);
  goBackEle.addEventListener('tap', submitPersonInfo);

  mui.back = backSubmit;
  app.deviceType = app.clientType.versions.android ? 'android' : 'iphone';

  function readPerson() {
    http.getToken({
      url: API.getReadPerson,
      token: $state.token,
      deviceType: app.deviceType,
      success: function(res) {
        console.log('res-->>', res);
        if (res.code === 200) {
          var personInfo = res.data,
            wallet = {
              income: personInfo.income,
              score: personInfo.score
            };
          localStorage.setItem('$wallet', JSON.stringify(wallet));

          if (personInfo.first_agent_id === 10 && personInfo.second_agent_id === 22) {
            $('#vip-confirm').modal({
              relatedTarget: this,
              closeViaDimmer: false,
              onConfirm: function() {
                console.log('this-->>', this);
                /* console.log('arguments-->>', arguments);
                $('#vip-confirm').modal('close'); */
                buildVIP();
              },
              onCancel: function() {
                console.log('arguments-->>', arguments);
                $('#vip-confirm').modal('close');

              }
            });
          }

          // 页面渲染数据
          renderPerson(personInfo);

        }
      },
      error: function(err) {
        console.log('请求失败')
      }
    });
  }

  // 我的二维码
  function buildQrcode() {
    $('#build_qrcode').on('click', function() {
      var tjCode = 'TJ' + app.createOrderNo().substr(-6),
        tempAddr = 'http://fed.cypto.cn/pages/reg.html?tj_code=' + tjCode;

      $('#show_qrcode').empty().qrcode(tempAddr);
      $('mark').text(tjCode);
      $('#qrcode_prompt').modal('open');
    });
  }

  // 生成VIP
  function buildVIP() {
    var VIPInfo = {};

    VIPInfo.order_no = 'V' + app.createOrderNo();
    http.postToken({
      url: API.postBuildVIP,
      data: VIPInfo,
      token: $state.token,
      deviceType: app.clientType.versions.android ? 'android' : 'iphone',
      success: function(res) {
        console.log('res-->>', res);
        if (res.code === 200) {
          mui.toast('升级VIP...');

          location.href = './vip_pay.html?title=大管家VIP会员&order_no=' + VIPInfo.order_no;
        }
      },
      error: function(err) {
        console.log('请求失败');
      }
    });
  }

  // 页面渲染数据
  function renderPerson(person) {
    buildQrcode();

    // if (person.score) document.querySelector('.score').innerText = person.score;

    var personArr = Array.from(document.querySelectorAll('.person')),
      sex = ['男', '女'];
    personArr.map(function(value, index) {
      if (index === 0) {
        if (!person.user_nickname) return;
        personArr[index].innerText = person.user_nickname;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 1) {
        if (person.sex === undefined) return;
        personArr[index].innerText = sex[person.sex];
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 2) {
        if (!person.age) return;
        personArr[index].innerText = person.age;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 3) {
        if (!person.signature) return;
        personArr[index].innerText = person.signature;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 4) {
        if (!person.industry) return;
        personArr[index].innerText = person.industry;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 5) {
        if (!person.company) return;
        personArr[index].innerText = person.company;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 6) {
        if (!person.work) return;
        personArr[index].innerText = person.work;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 7) {
        if (!person.hometown) return;
        personArr[index].innerText = person.hometown;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 8) {
        if (!person.hobby) return;
        personArr[index].innerText = person.hobby;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 9) {
        if (!person.work_times) return;
        personArr[index].innerText = person.work_times;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 10) {
        if (!person.validate_name) return;
        personArr[index].innerText = person.validate_name;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 11) {
        if (!person.good_at) return;
        personArr[index].innerText = person.good_at;
        return personArr[index].classList.add('pc-color-black');
      }
      if (index === 12) {
        if (!person.certificates) return;
        personArr[index].innerText = person.certificates;
        return personArr[index].classList.add('pc-color-black');
      }

    });
  }

  // 检查用户是否有密码,若无设置
  function havePassword() {
    var reqData = {};
    http.getToken({
      url: API.getHavePassword,
      token: $state.token,
      deviceType: app.deviceType,
      success: function(res) {
        console.log('res-->>', res);

        addPassword.call(this, res);
      },
      error: function(err) {
        console.log('请求失败')
      }
    });
  }

  function addPassword(res) {
    if (res.code === 10002) {
      $('#my-prompt').modal({
        relatedTarget: this,
        onConfirm: function(e) {
          console.log('你输入的是：' + e.data || '');
          this.options.closeOnConfirm = true;
          var fillVal = e.data;
          if (fillVal.length < 8) {
            this.options.closeOnConfirm = false;
            // this.modal('open');
            return mui.toast('密码小于8位');
          }
          if (fillVal.length > 16) {
            this.options.closeOnConfirm = false;
            return mui.toast('密码大于16位');
          }

          http.postToken({
            url: API.postAddPassword,
            data: {
              password: fillVal
            },
            token: $state.token,
            deviceType: app.deviceType,
            success: function(res) {
              console.log('res-->>', res);
              if (res.code === 200) {
                mui.toast('设置登录密码成功');
              }
            },
            error: function(err) {
              console.log('请求失败');
            }
          });
        }
      });
    }
  }

  function setHobby(e) {
    hobbySel.show(function(items) {
      var selVal = items[0].text;
      personInfo.hobby = selVal;
      showHobbyEle.innerText = selVal;
      showHobbyEle.classList.add('pc-color-black');
    });
  }

  function setHometown(e) {
    hometownSel.show(function(items) {
      var selVal = items[0].text;
      personInfo.hometown = selVal;
      showHometownEle.innerText = selVal;
      showHometownEle.classList.add('pc-color-black');
    });
  }

  function setWork(e) {
    e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug，使用plus.nativeUI.prompt会造成输入法闪一下又没了
    var btnArray = ['取消', '确定'];
    mui.prompt('请输入你的职业：', '真实职业可创造更多话题', '职业', btnArray, function(e) {
      if (e.index == 1) {
        if (!e.value) return;
        personInfo.work = e.value;
        showWorkEle.innerText = e.value;
        showWorkEle.classList.add('pc-color-black');
      } else {
        // showWorkEle.innerText = '你点了取消按钮';
        mui.toast('你点了取消按钮');
      }
    });

    /* mui.plusReady(function() {
      plus.nativeUI.prompt('输入名字', function(e) {
        // console.log(((e.index == 0) ? '确认，，' : '取消。。') + e.value);
        if (e.index == 0) {
          if (!e.value) return;
          showWorkEle.innerText = e.value;
          showWorkEle.classList.add('pc-color-black');
        } else {
          plus.nativeUI.toast('你点了取消按钮');
        }
      }, '职业', '真实职业可创造更多话题', ['确认', '取消']);
    }); */
  }

  function setCompany(e) {
    e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug，使用plus.nativeUI.prompt会造成输入法闪一下又没了
    var btnArray = ['取消', '确定'];
    mui.prompt('请输入你的公司：', '真实公司可创造更多话题', '公司', btnArray, function(e) {
      if (e.index == 1) {
        if (!e.value) return;
        personInfo.company = e.value;
        showCompanyEle.innerText = e.value;
        showCompanyEle.classList.add('pc-color-black');
      } else {
        // showCompanyEle.innerText = '你点了取消按钮';
        mui.toast('你点了取消按钮');
      }
    })
  }

  function setIndustry(e) {
    industrySel.show(function(items) {
      var selVal = items[0].text;
      personInfo.industry = selVal;
      showIndustryEle.innerText = selVal;
      showIndustryEle.classList.add('pc-color-black');
    });
  }

  function setSignature(e) {
    e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug，使用plus.nativeUI.prompt会造成输入法闪一下又没了
    var btnArray = ['取消', '确定'];
    mui.prompt('请输入你的签名：', '简单介绍一下自己吧', '签名', btnArray, function(e) {
      if (e.index == 1) {
        if (!e.value) return;
        personInfo.signature = e.value;
        showSignatureEle.innerText = e.value;
        showSignatureEle.classList.add('pc-color-black');
      } else {
        // showSignatureEle.innerText = '你点了取消按钮';
        mui.toast('你点了取消按钮');
      }
    })
  }

  function setGoodat(e) {
    e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug，使用plus.nativeUI.prompt会造成输入法闪一下又没了
    var btnArray = ['取消', '确定'];
    mui.prompt('请输入你的擅长：', '说出你的能力...', '擅长', btnArray, function(e) {
      if (e.index == 1) {
        if (!e.value) return;
        personInfo.signature = e.value;
        showGoodatEle.innerText = e.value;
        showGoodatEle.classList.add('pc-color-black');
      } else {
        // showGoodatEle.innerText = '你点了取消按钮';
        mui.toast('你点了取消按钮');
      }
    })
  }

  function setAge(e) {
    ageSel.show(function(items) {
      var selVal = items[0].text;
      personInfo.age = selVal;
      showAgeEle.innerText = selVal;
      showAgeEle.classList.add('pc-color-black');
    });
  }

  function setGender(e) {
    genderSel.show(function(items) {
      var selVal = items[0].text;
      personInfo.sex = selVal === '男' ? 0 : 1;
      showGenderEle.innerText = selVal;
      showGenderEle.classList.add('pc-color-black');
      //返回 false 可以阻止选择框的关闭
      //return false;
    });
  }

  function setName(e) {
    e.detail.gesture.preventDefault(); //修复iOS 8.x平台存在的bug，使用plus.nativeUI.prompt会造成输入法闪一下又没了
    var btnArray = ['取消', '确定'];
    mui.prompt('请输入你的昵称：', '起个昵称吧', '昵称', btnArray, function(e) {
      if (e.index == 1) {
        if (!e.value) return;
        personInfo.user_nickname = e.value;
        showNameEle.innerText = e.value;
        showNameEle.classList.add('pc-color-black');
      } else {
        // showNameEle.innerText = '你点了取消按钮';
        mui.toast('你点了取消按钮');
      }
    })
  }

  function toUploadZizhi() {
    mui.openWindow({
      id: 'uploadZizhi',
      url: './upload_zizhi.html',
      show: {
        aniShow: 'pop-in'
      },
      waiting: {
        autoShow: false
      }
    });
  }

  function toValidateName() {
    mui.openWindow({
      id: 'validateName',
      url: './validate_name.html',
      show: {
        aniShow: 'pop-in'
      },
      waiting: {
        autoShow: false
      }
    });
  }

  var submitCount = 0;

  function submitPersonInfo() {
    if (Object.keys(personInfo).length === 0) return history.back();

    if (submitCount === 1) return history.back();
    submitCount++;
    http.postToken({
      url: API.postEditPerson,
      data: personInfo,
      token: $state.token,
      deviceType: app.clientType.versions.android ? 'android' : 'iphone',
      success: function(res) {
        console.log('res-->>', res);
        if (res.code === 200) {
          mui.toast('修改成功');
          history.back();
        }
        if (res.code === 404) mui.toast('修改失败');
      },
      error: function(err) {
        console.log('请求失败')
      }
    });

  }

  var submitCount1 = 0;

  function backSubmit(event) {
    if (Object.keys(personInfo).length === 0) return;

    if (submitCount1 === 1) return;
    submitCount1++;
    http.postToken({
      url: API.postEditPerson,
      data: personInfo,
      token: $state.token,
      deviceType: app.clientType.versions.android ? 'android' : 'iphone',
      success: function(res) {
        console.log('res-->>', res);
        mui.toast('修改成功');
        history.back();
      },
      error: function(err) {
        console.log('请求失败')
      }
    });
  }

  mui.plusReady(function() {
    plus.share.getServices(function(s) {
      if (s && s.length > 0) {
        for (var i = 0; i < s.length; i++) {
          var t = s[i];
          shares[t.id] = t;
        }
      }
    }, function() {
      console.log("获取分享服务列表失败");
    });

    setTimeout(function() {
      defaultImg();
      setTimeout(function() {
        initImgPreview();
      }, 300);
    }, 500);

    // 更换头像
    mui('.mui-table-view-cell').on('tap', '#head', replaceAvatar);

  });


  function replaceAvatar(e) {
    if (mui.os.plus) {
      var a = [{
        title: "拍照"
      }, {
        title: "从手机相册选择"
      }];

      plus.nativeUI.actionSheet({
        title: "修改头像",
        cancel: "取消",
        buttons: a
      }, function(b) {
        switch (b.index) {
          case 0:
            break;
          case 1:
            getImage();
            break;
          case 2:
            galleryImg();
            break;
          default:
            break
        }
      })
    }
  }

  function addAvatar(filePath) {
    http.post(API.postAddAvatar, {
      filePath
    }, function(res) {
      console.log('res-->>', res);
    });
  }

  function getImage() {
    var c = plus.camera.getCamera();
    c.captureImage(function(e) {
      plus.io.resolveLocalFileSystemURL(e, function(entry) {
        // var s = entry.toLocalURL() + "?version=" + new Date().getTime();
        console.log(s);

        var filePath = entry.toLocalURL();
        addAvatar(filePath);

        // document.getElementById("head-img").src = s;
        document.getElementById("head-img1").src = s;
        //变更大图预览的src
        //目前仅有一张图片，暂时如此处理，后续需要通过标准组件实现
        document.querySelector("#__mui-imageview__group .mui-slider-item img").src = s + "?version=" + new Date().getTime();;;
      }, function(e) {
        console.log("读取拍照文件错误：" + e.message);
      });
    }, function(s) {
      console.log("error" + s);
    }, {
      filename: "_doc/head.jpg"
    })
  }

  function galleryImg() {
    plus.gallery.pick(function(a) {
      plus.io.resolveLocalFileSystemURL(a, function(entry) {
        plus.io.resolveLocalFileSystemURL("_doc/", function(root) {
          root.getFile("head.jpg", {}, function(file) {
            //文件已存在
            file.remove(function() {
              console.log("file remove success");
              entry.copyTo(root, 'head.jpg', function(e) {
                  var e = e.fullPath + "?version=" + new Date().getTime();
                  // document.getElementById("head-img").src = e;
                  document.getElementById("head-img1").src = e;
                  //变更大图预览的src
                  //目前仅有一张图片，暂时如此处理，后续需要通过标准组件实现
                  document.querySelector("#__mui-imageview__group .mui-slider-item img").src = e + "?version=" + new Date().getTime();;
                },
                function(e) {
                  console.log('copy image fail:' + e.message);
                });
            }, function() {
              console.log("delete image fail:" + e.message);
            });
          }, function() {
            //文件不存在
            entry.copyTo(root, 'head.jpg', function(e) {
                var path = e.fullPath + "?version=" + new Date().getTime();
                // document.getElementById("head-img").src = path;
                document.getElementById("head-img1").src = path;
                //变更大图预览的src
                //目前仅有一张图片，暂时如此处理，后续需要通过标准组件实现
                document.querySelector("#__mui-imageview__group .mui-slider-item img").src = path;
              },
              function(e) {
                console.log('copy image fail:' + e.message);
              });
          });
        }, function(e) {
          console.log("get _www folder fail");
        })
      }, function(e) {
        console.log("读取拍照文件错误：" + e.message);
      });
    }, function(a) {}, {
      filter: "image"
    })
  };

  function defaultImg() {
    if (mui.os.plus) {
      plus.io.resolveLocalFileSystemURL("_doc/head.jpg", function(entry) {
        var s = entry.fullPath + "?version=" + new Date().getTime();;
        // document.getElementById("head-img").src = s;
        document.getElementById("head-img1").src = s;
      }, function(e) {
        //      document.getElementById("head-img").src = '../images/avator-demo.jpg';
        document.getElementById("head-img1").src = '../images/avator-demo.jpg';
      })
    } else {
      // document.getElementById("head-img").src = '../images/avator-demo.jpg';
      document.getElementById("head-img1").src = '../images/avator-demo.jpg';
    }

  }

  document.getElementById("head-img1").addEventListener('tap', function(e) {
    e.stopPropagation();
  });

  function initImgPreview() {
    var imgs = document.querySelectorAll("img.mui-action-preview");
    imgs = mui.slice.call(imgs);
    if (imgs && imgs.length > 0) {
      var slider = document.createElement("div");
      slider.setAttribute("id", "__mui-imageview__");
      slider.classList.add("mui-slider");
      slider.classList.add("mui-fullscreen");
      slider.style.display = "none";
      slider.addEventListener("tap", function() {
        slider.style.display = "none";
      });
      slider.addEventListener("touchmove", function(event) {
        event.preventDefault();
      })
      var slider_group = document.createElement("div");
      slider_group.setAttribute("id", "__mui-imageview__group");
      slider_group.classList.add("mui-slider-group");
      imgs.forEach(function(value, index, array) {
        //给图片添加点击事件，触发预览显示；
        value.addEventListener('tap', function() {
          slider.style.display = "block";
          _slider.refresh();
          _slider.gotoItem(index, 0);
        })
        var item = document.createElement("div");
        item.classList.add("mui-slider-item");
        var a = document.createElement("a");
        var img = document.createElement("img");
        img.setAttribute("src", value.src);
        a.appendChild(img)
        item.appendChild(a);
        slider_group.appendChild(item);
      });
      slider.appendChild(slider_group);
      document.body.appendChild(slider);
      var _slider = mui(slider).slider();
    }
  }

  if (mui.os.stream) {
    document.getElementById("check_update").display = "none";
  }
</script>

</html>